package buff

import (
	"encoding/json"
	"errors"
	"fmt"
	"kop/modules/configuration/client"
	"kop/modules/configuration/configuration/bufftype"
	"kop/util/log"
)

func init() {

	var b = client.Load("TreasureBuff")
	if err := json.Unmarshal(b, &Configs); err != nil {
		panic(err)
	}

	log.Info("Load TreasureBuff.json success.")
}

type Conf struct {
	ID       int32  // 增益ID
	Name     string // 增益名称
	Quality  int32  // 增益品质
	Weight   int32  // 权重：1:10000
	BuffType bufftype.Type
	Camp     int32   // 阵营条件
	Value    float64 // 效果值
}

func (b Conf) GetWeight() int32 {
	return b.Weight
}

func (b Conf) GetID() int32 {
	return b.ID
}

var Configs = map[int32]Conf{}

func GetByBuffID(BuffID int32) (Conf, error) {

	var conf, ok = Configs[BuffID]
	if ok {
		return conf, nil
	}

	return Conf{}, errors.New(fmt.Sprintf("BuffID not found [%d]", BuffID))
}
